<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var str="helloworld";
    var count=0;
    for(var index=str.indexOf("l");index!=-1;index=str.indexOf("l",index+1)){
        count++;
    }
    alert(count);
</script>
</body>
</html>